<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>工作记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-table
            :data="arryList"
            border
            style="width: 100%">
          <el-table-column
              prop="id"
              label="ID"
              align="center"
              width="80">
          </el-table-column>
          <el-table-column
              prop="create_time"
              label="创建时间"
              align="center"
              width="160">
          </el-table-column>
          <el-table-column
              label="提交人"
              align="center">
            <template slot-scope="scope">
              {{ scope.row.user ? scope.row.user.realname : '未提交' }}
            </template>
          </el-table-column>
          <el-table-column
              label="文件"
              align="center">
            <template slot-scope="scope">
              <div v-for="item in scope.row.file">
                <btn_file :option="item"></btn_file>
              </div>
            </template>
          </el-table-column>
          <!--          <el-table-column-->
          <!--              label="批注"-->
          <!--              align="center">-->
          <!--            <template slot-scope="scope">-->
          <!--              <el-popover-->
          <!--                  v-if="scope.row.remark"-->
          <!--                  placement="left-start"-->
          <!--                  title="批注内容"-->
          <!--                  width="300"-->
          <!--                  trigger="click">-->
          <!--                <div class="remark">-->
          <!--                  <div v-html="scope.row.remark" class="remarkBody"></div>-->
          <!--                  <div v-if="scope.row.remark_file">-->
          <!--                    附件：-->
          <!--                    <div>-->
          <!--                      <div v-for="item in scope.row.fileList">-->
          <!--                        <btn_file :option="item"></btn_file>-->
          <!--                      </div>-->
          <!--                    </div>-->
          <!--                  </div>-->
          <!--                </div>-->
          <!--                <span slot="reference" class="tablelineBtn">查看批注</span>-->
          <!--              </el-popover>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column
              label="批注"
              align="center"
              width="100">
            <template slot-scope="scope">
              <span class="tablelineBtn" @click="lookPizhu(scope.row.id)">查看批注</span>
            </template>
          </el-table-column>
          <el-table-column
              label="操作"
              align="center"
              width="160">
            <template slot-scope="scope">
              <el-button type="primary" size="small" plain
                         @click="noteId=scope.row.id,noteRemark=scope.row.remark,remarkVisible=true">
                批注
              </el-button>
              <el-button type="danger" size="small" plain @click="handleDetel(scope.row.id)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              layout="prev, pager, next"
              :total="page.total"
              :page-size="page.pagesize"
              @current-change="handleSizeChange">
          </el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
      </div>
    </div>
    <remarkFile :visible.sync="remarkVisible" :noteId="noteId" @getFileListFn="getFileListFn"
                :noteRemark="noteRemark" remarkType="2"></remarkFile>
    <pizhu :visible.sync="pizhuVisible" :fileId="fileId" @getFileListFn="getFileListFn" remarkType="2"></pizhu>
  </div>
</template>

<script>
import {noteList, noteListDelete} from "@/api/admin/outineWorke"
import {pagination} from '@/utils/util.js'
import remarkFile from "./remarkFile";
import pizhu from "./pizhu";

export default {
  props: ['visible', 'workId', 'userListData'], // commoent 学生点评 collection 学生采集
  components: {
    remarkFile,
    pizhu
  },
  data() {
    return {
      dialogVisible: false,
      editStatus: true,
      remarkVisible: false,
      pizhuVisible: false,
      arryList: [],
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      noteId: 0,
      noteRemark: '',
      fileId: 0
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.getFileListFn()
      } else {
        this.editForm = {
          evaluation: '',
          strategy: '',
          share: ''
        }
        this.arryList = []
      }
    }
  },
  created() {
  },
  methods: {
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 获取记录
    getFileListFn() {
      noteList({p: this.page.pageindex, cate_id: this.workId, user_id: this.userListData.id}).then(res => {
        for (let item of res.list.data) {
          item.file = JSON.parse(item.file)
          if (item.remark_file) {
            item.fileList = JSON.parse(item.remark_file)
          }
        }
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    handleDetel(id) {
      this.$confirm('确认删除该工作记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(id)
      }).catch(() => {
      })
    },
    detelRespon(id) {
      noteListDelete({id: id}).then(res => {
        if (!res.code) {
          this.$message.success(res.msg)
          this.getFileListFn()
        }
      })
    },
    lookPizhu(id) {
      console.log(id)
      this.fileId = id;
      this.pizhuVisible = true;
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 76%;
  height: 550px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.hearder-search {
  display: flex;
  align-items: center;
}

.remarkBody {
  white-space: pre-wrap
}
</style>


